#include<func.h>
#include<mysql/mysql.h>

int main()
{
    MYSQL* mysql=mysql_init(NULL);
    MYSQL_RES * res;
    MYSQL_ROW row;
    if(mysql==NULL)
    {
        printf("%s\n",mysql_error(mysql));
    }

    if(!mysql_real_connect(mysql,"localhost","root","123456","homework",0,NULL,0))
    {
        printf("%s\n",mysql_error(mysql));
    }

    int ret=mysql_query(mysql,"select * from s ");
    if(ret==0)
        printf("执行成功\n");
    else
        printf("执行失败\n");
   res= mysql_store_result(mysql);
   if(res==NULL)
   {
      printf("结果获取出错\n");
   }
   unsigned int num =mysql_num_rows(res);
  if(num==0)
  {
      printf("结果获取出错\n");
  }

  while((row=mysql_fetch_row(res)))
  {
      for(unsigned int i=0;i<mysql_num_fields(res);i++)
      {
          printf("|%10s ",row[i]);
      }
      printf("\n");
  }
  mysql_free_result(res);
    mysql_close(mysql);
}
